package com.cjm.algorithm.tree;

import com.cjm.algorithm.TreeNode;

public class Ti111 {
    int maxDep = Integer.MAX_VALUE;
    public int minDepth(TreeNode root) {
        maxDep = Integer.MAX_VALUE;
        if (root == null) return 0;
        method111(root, 1);
        return maxDep;
    }

    private void method111(TreeNode root, int i) {
        if (root.left == null && root.right == null) {
            maxDep = Math.min(i, maxDep);
            return;
        }
        if (root.left != null) method111(root.left, i + 1);
        if (root.right != null) method111(root.right, i + 1);
    }
}
